package huu.bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author huu
 * @create 2025-08-26-23:18
 * @description: 面向流的
 */
public class BioServer {

    public static void main(String[] args) throws IOException {
        //新建一个Socket服务器
        ServerSocket socket = new ServerSocket(8080);
        while(true){
            //等待客户端连接,阻塞链接
            Socket accept = socket.accept();
            //获取输入流
            InputStream inputStream = accept.getInputStream();
            byte[] bytes = new byte[1024];
            int length;
            //BIO--一个线程最多处理一个请求, NIO是不阻塞的
            //只要read不返回-1,就会一直阻塞
            while((length = inputStream.read(bytes)) != -1){
                String message = new String(bytes,0,length);
                System.out.println(message);
            }
        }

    }
}
